<template>
  <div class="container">
    <el-dialog
      title="订单详情"
      :visible.sync="particularsDialogs.centerDialogVisible"
      @open="getData"
      center
      width="1200px"
    >
      <el-table
        :data="tableData"
        border
        :summary-method="getSummaries"
        show-summary
        style="width: 100%"
        empty-text="暂无数据"
      >
        <el-table-column
          prop="goods_name"
          label="商品名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="erp_goods_code"
          label="商品编码"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="goods_spec"
          label="规格"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="category_code"
          label="分类编码"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="category_name"
          label="分类名称"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="goods_unit"
          label="单位"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="bar_code"
          label="条形码"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="purchasePrice"
          label="采购加价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="stockRemoval"
          label="出库价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="totalPrices"
          label="出库价总价"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="costPrices"
          label="成本总价"
          align="center"
        ></el-table-column>
        <el-table-column prop="cost_price" label="成本价" align="center">
        </el-table-column>
        <el-table-column prop="order_num" label="数量" align="center">
        </el-table-column>

        <el-table-column prop="markup" label="加价" align="center">
        </el-table-column>
        <el-table-column prop="box_qty" label="件数" align="center">
        </el-table-column>
        <el-table-column prop="withholding_fee" label="预提" align="center">
        </el-table-column>
        <el-table-column prop="rk_spec" label="入库规格" align="center">
        </el-table-column>
        <el-table-column prop="produce_date" label="生产日期" align="center">
        </el-table-column>
        <el-table-column prop="shelf_life" label="保质期（天）" align="center">
        </el-table-column>
        <el-table-column prop="package.name" label="包装箱" align="center"></el-table-column>
        <el-table-column prop="package_box_spec" label="包装箱规格" align="center"></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { findOrderInfo, editOrderInfo } from "@/api/superOrder/superOrderList";
export default {
  props: {
    particularsDialogs: Object,
  },
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    confirm() {
      this.particularsDialogs.centerDialogVisible = false;
    },
    getData() {
      let data = {
        id: this.particularsDialogs.id,
      };
      findOrderInfo(data).then((res) => {
        if (res.code == 0) {
          res.data.info.order_goods.forEach((result) => {
            result.costPrices =
        parseFloat(result.cost_price) * parseFloat(result.order_num);
            result.purchasePrice = result.buyerprofit_price;
            result.stockRemoval =
              result.order_goods_status > 0
                ? result.delivery_price
                : (
                    parseFloat(result.cost_price) +
                    parseFloat(result.markup) +
                    parseFloat(result.withholding_fee) +
                    parseFloat(result.purchasePrice)
                  ).toFixed(4);
            result.totalPrices = (
              result.stockRemoval * result.order_num
            ).toFixed(4);
          });
          this.tableData = res.data.info.order_goods;
        }
      });
    },
     //总价
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总价";
          return;
        }
        const values = data.map((item) => Number(item[column.property]));
        if (!values.every((value) => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          if (index != 10 ) {
            sums[index] = "";
          } else {
            sums[index] = sums[index].toFixed(4);
          }
        } else {
          sums[index] = "";
        }
      });

      return sums;
    },
    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;
      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;
      this.getData();
    },
  },
};
</script>
<style scoped>
.pagination {
  text-align: right;
  padding: 10px;
}
</style>